"""
站内信页面
"""

from selenium.webdriver.common.by import By
from page.base_page import BasePage


class MailPage(BasePage):
    url = "/crm/index.php?m=message"
    # 写信定位器
    send_message_locator = (By.ID, "send")
    # 全选按钮定位器
    choose_locator = (By.CSS_SELECTOR, '#ta1 > input')
    # 内容定位器
    content_locator = (By.CSS_SELECTOR, '#dialog-message-send > form > table > tbody > tr:nth-child(2) > td:nth-child(2) > textarea')
    # 发送定位器
    sending_locator = (By.CSS_SELECTOR, '#dialog-message-send > form > table > tfoot > tr > td:nth-child(2) > input.btn.btn-primary')
    # 发件箱定位器
    outbox_locator = (By.ID, 't2')
    # 勾选第一条信息
    del_choose_locator = (By.CLASS_NAME, 'send_check_list')
    # 全部勾选定位器
    del_all_choose_locator = (By.ID, 'send_check_all')
    # 批量操作按钮定位器
    bulk_operations_locator = (By.LINK_TEXT, '批量操作')
    # 删除按钮定位器
    delete_locator = (By.ID, 'delete_send')
    # 发送成功定位器
    sending_ok = (By.XPATH,'/html/body/div[5]/div[2]')



    # 获取当前页面地址
    def get_current_url(self):
        return self.driver.current_url

    # 点击写信
    def click_message(self):
        self.driver.find_element(*self.send_message_locator).click()

    # 点击全部选择
    def click_choose(self):
        self.driver.find_element(*self.choose_locator).click()

    # 输入内容
    def input_content(self,content):
        self.driver.find_element(*self.content_locator).send_keys(content)

    # 点击发送
    def click_sending(self):
        self.driver.find_element(*self.sending_locator).click()

    # 点击发件箱
    def click_outbox(self):
        self.driver.find_element(*self.outbox_locator).click()

    # 点击勾选第一条信息
    def click_del_choose(self):
        self.driver.find_element(*self.del_choose_locator).click()

    # 点击全部勾选
    def click_del_all_choose(self):
        self.driver.find_element(*self.del_all_choose_locator).click()

    # 点击批量操作
    def click_bulk_operations(self):
        self.driver.find_element(*self.bulk_operations_locator).click()

    # 点击删除
    def click_delete(self):
        self.driver.find_element(*self.delete_locator).click()
        self.driver.switch_to.alert.accept()

    # 获取标签的值
    def save_success(self):
        success = self.driver.find_element(*self.sending_ok).get_attribute("class")
        return success
